﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RMS.Models;
using RMS.Models.Repository;
using System.Web.ModelBinding;

namespace RMS.Pages.Admin
{
    public partial class ViewReservations : System.Web.UI.Page
    {
        private Repository repo = new Repository();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public IEnumerable<Reservation> GetReservations()
        {
            int retID = (int)Session["RetreatID"];

            return repo.Reservations.Where(r => r.Res_RetID == retID);

            //IEnumerable<Reservation> test = repo.Reservations.Where(r => r.Res_RetID == retID);
            //return test;
        }

        public void UpdateReservation(int resID)
        {
            Reservation res = repo.Reservations.Where(r => r.ResId == resID).FirstOrDefault();

            if(res != null && TryUpdateModel (res,
                new FormValueProvider(ModelBindingExecutionContext)))
            {
                repo.SaveReservation(res);
            }
        }

        public void DeleteReservation(int ResID)
        {
            Reservation res = repo.Reservations.Where(r => r.ResId == ResID).FirstOrDefault();

            if (res != null)
            {
                repo.DeleteReservation(res);
            }
        }

        // For setting up true/false comboboxes
        public string returnOpposite(Boolean str)
        {

            if (str == false)
            {
                return "True";
            }
            else
                return "False";
        }

        public string checkOrCredit(Boolean check, Boolean credit)
        {
            string str = "";
            if (check == true)
            {
                str += "Check";
            }
            else if (credit == true)
            {
                str += "Credit";
            }
            else
            {
                str += "No payment option selected.";
            }

            return str;
        }
    }
}